<%@page contentType="text/html; charset=utf-8"%>
<%@include file="/WEB-INF/views/common/tags.jspf" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>系统用户管理</title>
	<%@include file="/WEB-INF/views/common/header.jspf" %>
</head>

<body>

	<div id="dg">
		<div id="toolbars">
			<form id="searchForm">
				<div class="search-bar">
					<div class="bar-row">
						<button type="button" onclick="form_dialog('add');" class="btn btn-green btn-xs height-25 mt-3 float-left"><div class='icon-div'><i class='fa fa-plus fa-120 pt-2'></i></div> 新增</button>
						<button type="button" onclick="form_dialog('update');" class="btn btn-blue btn-xs height-25 mt-3 ml-1 float-left"><div class='icon-div'><i class='fa fa-pencil fa-120 pt-2'></i></div> 编辑</button>
						<button type="button" onclick="del();" class="btn btn-red btn-xs height-25 mt-3 ml-1 float-left"><div class='icon-div'><i class='fa fa-trash fa-120 pt-2'></i></div> 删除</button>
						<button type="button" onclick="reload();" class="btn btn-purple1 btn-xs height-25 mt-3 ml-1 float-left"><div class='icon-div'><i class='fa fa-refresh fa-120 pt-2'></i></div> 刷新</button>
						
						<button type="button" onclick="admin_change_pwd_dialog();" class="btn btn-blue1 btn-xs height-25 mt-3 ml-10 float-left"><div class='icon-div'><i class='fa fa-gears fa-120 pt-2'></i></div> 修改密码</button>
						<button type="button" onclick="allotRole_dialog();" class="btn btn-blue1 btn-xs height-25 mt-3 ml-1 float-left"><div class='icon-div'><i class='fa fa-gears fa-120 pt-2'></i></div> 分配角色</button>
						
						<button id="already" type="button" onclick="alreadyRemoved();" class="btn btn-blue1 btn-xs height-25 mt-3 ml-1 ml-l10 float-left"><div class='icon-div'><i class='fa fa-gears fa-120 pt-2'></i></div> 已删除</button>
						<button id="recover" type="button" onclick="recoverRemoved();" class="btn btn-blue1 btn-xs height-25 mt-3 ml-1 ml-l10 float-left" style="display:none"><div class='icon-div'><i class='fa fa-gears fa-120 pt-2'></i></div> 恢复</button>
						<button id="physics" type="button" onclick="physicsRemoved();" class="btn btn-blue1 btn-xs height-25 mt-3 ml-1 float-left" style="display:none"><div class='icon-div'><i class='fa fa-gears fa-120 pt-2'></i></div> 物理删除</button>
					</div>
					
					<div class="bar-row">
						<div class="bar-input">
		            		<input name="quickSearch" class="easyui-searchbox" data-options="searcher:quickSearch, width: 150, height: 25,prompt: '快速搜索...'" />
	            		</div>
						<div class="bar-input">
		            		<select name="sex" class="easyui-combobox" data-options="panelHeight:'auto',editable:false" style="height:25px;">
								<option value="">请选择</option>
								<option value="男">男</option>
								<option value="女">女</option>
							</select>
	            		</div>
						<div class="bar-input">
		            		<input id="st" name="startTime" class="Wdate" style="height:23px;" type="text" onFocus="WdatePicker({
							isShowClear:true,
							readOnly:true,
							maxDate:'#F{$dp.$D(\'et\')||\'2020-10-01\'}'
							})"/>
							至
		            		<input id="et" name="endTime" class="Wdate" style="height:23px;" type="text" onFocus="WdatePicker({
							isShowClear:true,
							readOnly:true,
							minDate:'#F{$dp.$D(\'st\')}',
							maxDate:'2120-10-01'
							})"/>
	            		</div>
	            		<button type="button" onclick="searchBox();" class="btn btn-purple2 btn-xs height-25 mt-3 float-left"><div class='icon-div'><i class='fa fa-search fa-120 pt-1'></i></div> 搜索</button>
	            		<button type="button" onclick="searchClear();" class="btn btn-warning btn-xs height-25 mt-3 ml-1 float-left"><div class='icon-div'><i class='fa fa-undo fa-120 pt-2'></i></div> 重置</button>
					</div>
				</div>
				<input id="deleted" type="hidden" value="false"/>
			</form>
		</div>
	</div>
	
	
	<%@include file="/WEB-INF/views/common/script.jspf" %>
	<script>
	var $dg ;
	$(function(){
		$dg = $("#dg").datagrid({
			title: "系统用户管理",
            url: "${ctx}/admin/sys/user/datagrid",
            idField: "id", fit: true, 
            border: false, striped:true, pageSize: 30, pageList: [30,40,50,100,200,500,1000], 
            pagination: true, rownumbers: true, toolbar: "#toolbars", remoteSort: true, 
            sortName: 'createTime', sortOrder: 'desc', queryParams: {"deleted": false},
            frozenColumns: [[
                { field: "ck", checkbox: true },
                { field: "id", title: "ID", width: 80, sortable: true }
            ]],
            columns: [[
                { field: "username", title: "用户名", width: 120 },
                { field: "truename", title: "真实姓名", width: 120 },
                { field: "sex", title: "性别", width: 60, align: "center" },
                { field: "mobile_phone_number", title: "手机号码", width: 100 },
                { field: "email", title: "邮箱地址", width: 160 },
                { field: "status", title: "状态", width: 60, sortable: true, align: "center", formatter:function(value,row){
                	var t = "<span style='color: red;'>禁用</span>", f = "<span style='color: green;'>正常</span>" ;
                	return (value=="normal"?f:t) ;	
                }},
                { field: "admin", title: "是否管理员", width: 100, sortable: true, formatter:function(value,row){
                	var t = "<span style='color: red;'>管理员</span>", f = "<span style='color: green;'>非管理员</span>" ;
                	return (value?t:f) ;	
                }},
                { field: "createTime", title: "创建时间", width: 150, sortable: true }
            ]],
            onLoadSuccess: function(){
            	$.fn.datagrid.extensions.onLoadSuccess.apply(this, arguments);
            	$dg.datagrid('unselectAll');$dg.datagrid('clearSelections');
            },
            enableHeaderClickMenu: true, enableHeaderContextMenu: true, enableRowContextMenu: false
        });
	});
	function reload(){$dg.datagrid("reload") ;}
	function quickSearch(value,name){
		var o = {} ; o[name] = value ; $dg.datagrid("load",o);
	}
	function searchBox() {
		var search_form = $.webapp.serializeObject("#searchForm") ;
		if(search_form.quickSearch === "快速搜索...")search_form["quickSearch"]=null;
		search_form["deleted"] = ($("#deleted").val()=="false"? false : true) ;
		$dg.datagrid("load",search_form);
	}
	function searchClear() {
		$("#searchForm").form("clear") ;
		$("#deleted").val("false") ;
		$dg.datagrid("load",{"deleted": false});
		
		
		$("#already").show();
		$("#recover").hide();
		$("#physics").hide();
	}
	function getIds() {
		var rows = $dg.datagrid('getChecked');
		var ids = [];
		if (rows.length > 0) {
			for ( var i = 0; i < rows.length; i++) {
				if(undefined != rows[i].id && ""!=rows[i].id) {
					ids.push(rows[i].id);
				}
			}
		}
		return ids ;
	}	
	
	function form_dialog(formType) {
		var form_url = "${ctx}/admin/sys/user/form";
		if(formType === "update") {
			var ids = getIds() ;
			if(ids.length == 0) {alertify.warning("请选择一条记录！");return;}
			if(ids.length > 1) {alertify.warning("只能编辑一条记录！");return;}
			form_url = "${ctx}/admin/sys/user/form?id="+ids[0];
		}
		
		var $d = $.easyui.showDialog({
			href: form_url, title: '<div class="icon-div"><i class="fa fa-link fa-120 pt-2 fa-c-blue"></i></div> 表单', iniframe: false, topMost: true, iconCls : '',
			width: 750, height: 405, maximizable: true,
            enableApplyButton: false, enableCloseButton: false, enableSaveButton: false,
            buttons : [ 
              { text : '<i class="fa fa-save fa-120 mt-6 fa-c-green"></i> 应用', handler : function() { $.easyui.parent.submitForm($d, $dg, true) ; } },
              { text : '<i class="fa fa-save fa-120 mt-6 fa-c-blue"></i> 保存', handler : function() { $.easyui.parent.submitForm($d, $dg) ; } },
              { text : '<i class="fa fa-remove fa-120 mt-6 fa-c-red"></i> 关闭', handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	}
	
	function del() {
		if(getIds().length == 0) {alertify.warning("请选择一条记录！");return;}
		$.messager.confirm("您确定要进行该操作？", function (c) { 
			if(c) {
				$.easyui.loading({ msg: "数据删除中，请稍等..."});
				deletedAjax("${ctx}/admin/sys/user/delete", {"ids" : getIds().join(','), "type": true}) ;
			}
		});
	}
	function recoverRemoved() {
		if(getIds().length == 0) {alertify.warning("请选择一条记录！");return;}
		$.messager.confirm("您确定要进行该操作？", function (c) { 
			if(c) {
				$.easyui.loading({ msg: "恢复已删除用户，请稍等..."});
				deletedAjax("${ctx}/admin/sys/user/delete", {"ids" : getIds().join(','), "type": false}) ;
			}
		});
	}
	function physicsRemoved() {
		if(getIds().length == 0) {alertify.warning("请选择一条记录！");return;}
		$.messager.confirm("您确定要进行该操作？该操作不可逆！", function (c) { 
			if(c) {
				$.easyui.loading({ msg: "正在执行物理删除，请稍等..."});
				deletedAjax("${ctx}/admin/sys/user/deleteForPhysical", {"ids" : getIds().join(',')}) ;
			}
		});
	}
	function alreadyRemoved() {
		$("#deleted").val("true") ;
		quickSearch(true, "deleted");
		$("#already").hide();
		$("#recover").show();
		$("#physics").show();
	}
	function deletedAjax(url, params) {
		$.post(url, params, function(result) {
			if (result.status) {
				$dg.datagrid("unselectAll");$dg.datagrid("reload") ;
				alertify.success(result.message);
				$.easyui.loaded();
			} else {
				alertify.warning(result.message);
				$.easyui.loaded();
			}
		}, 'json').error(function() { $.easyui.loaded(); });
	}
	
	
	
	function allotRole_dialog() {
		var ids = getIds() ;
		if(ids.length == 0) {alertify.warning("请选择一条记录！");return;}
		
		var form_url = "${ctx}/admin/sys/user/ui_role/"+ids.join(",");
		var $d = $.easyui.showDialog({
			href: form_url, title: '<div class="icon-div"><i class="fa fa-link fa-120 pt-2 fa-c-blue"></i></div> 分配角色', iniframe: false, topMost: true, iconCls : '',
			width: 750, height: 405, maximizable: true,
            enableApplyButton: false, enableCloseButton: false, enableSaveButton: false,
            buttons : [ 
              { text : '<i class="fa fa-save fa-120 mt-6 fa-c-green"></i> 应用', handler : function() { $.easyui.parent.submitForm($d, $dg, true) ; } },
              { text : '<i class="fa fa-save fa-120 mt-6 fa-c-blue"></i> 保存', handler : function() { $.easyui.parent.submitForm($d, $dg) ; } },
              { text : '<i class="fa fa-remove fa-120 mt-6 fa-c-red"></i> 关闭', handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	}
	function admin_change_pwd_dialog() {
		var ids = getIds() ;
		if(ids.length == 0) {alertify.warning("请选择一条记录！");return;}
		
		var form_url = "${ctx}/admin/sys/user/ui_change_pwd/"+ids.join(",");
		var $d = $.easyui.showDialog({
			href: form_url, title: '<div class="icon-div"><i class="fa fa-link fa-120 pt-2 fa-c-blue"></i></div> 修改用户密码', iniframe: false, topMost: true, iconCls : '',
			width: 450, height: 155, maximizable: true,
            enableApplyButton: false, enableCloseButton: false, enableSaveButton: false,
            buttons : [ 
              { text : '<i class="fa fa-save fa-120 mt-6 fa-c-blue"></i> 确定', handler : function() { $.easyui.parent.submitForm($d, $dg) ; } },
              { text : '<i class="fa fa-remove fa-120 mt-6 fa-c-red"></i> 关闭', handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	}
	</script>
</body>
</html>

